import Vue from 'vue'
import Vuex from 'vuex'
import * as types from './types'

Vue.use(Vuex)
const state = {
  regularInfo: {},
  talkInfo: {}, // 文字聊天医生详情
  sessionsList: [], // 最近聊天列表
  loginStatus: Boolean,
  ifIphonex: Boolean,
  phoneCamera: Boolean,
  ifVideoing: false
}
var copyState = deepClone(state)
function deepClone (obj) {
  var newObj = obj instanceof Array ? [] : {}
  for (var i in obj) {
    newObj[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i]
  }
  return newObj
}
const mutations = {
  resetState (state) {
    for (var i in copyState) {
      state[i] = copyState[i] // 递归赋值
    }
  },
  [types.TALK_INFO]: (state, data) => {
    state.talkInfo = data
  },
  [types.REGULAR_INFO]: (state, data) => {
    state.regularInfo = data
  },
  [types.SESSIONS_LIST]: (state, data) => {
    state.sessionsList = data
  },
  [types.LOGIN_STATUS]: (state, data) => {
    state.loginStatus = data
  },
  [types.if_IPHONEX]: (state, data) => {
    state.ifIphonex = data
  },
  [types.if_VIDEOING]: (state, data) => {
    state.ifVideoing = data
  },
  [types.PHONE_CAMERA]: (state, data) => {
    state.phoneCamera = data
  }
}

export default new Vuex.Store({
  state,
  mutations
})
